//
//  MSChainMaker.h
//  MSDemo
//
//  Created by mac on 2021/6/18.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef NS_OPTIONS(NSUInteger, MSBorderSideType) {
    MSBorderSideTypeAll = 0,
    MSBorderSideTypeTop = (1 << 0),
    MSBorderSideTypeLeft = (1 << 1),
    MSBorderSideTypeBottom = (1 << 2),
    MSBorderSideTypeRight = (1 << 3),
};

typedef NS_ENUM(NSUInteger, MSButtonModel)
{
    MSButtonModelDefault = 0,            ///< 默认，左侧图片+右侧文字 水平居中
    MSButtonModelTextAndImgHorizontal,   ///< 左侧文字+右侧图片 水平居中
    MSButtonModelTextAndImgVertical,     ///< 上面文字+下面图片 垂直居中
    MSButtonModelImgAndTextVertical,     ///<上面图片+下面文字 垂直居中
};

NS_ASSUME_NONNULL_BEGIN

/** 链式编程 */
@interface MSChainMaker : NSObject

UIView *ms_newView(void);
UIScrollView *ms_newScrollView(void);
UIButton *ms_newButton(void);
UILabel *ms_newLabel(void);
UIImageView *ms_newImageView(void);
UITableView *ms_newIableView(UITableViewStyle style);
UICollectionView *ms_newCollectionView(UICollectionViewLayout *layout);
CAGradientLayer *ms_newGradientLayer(void);
/** 控件对象 */
@property (nonatomic, weak) id originalObj;


#pragma mark - view
/** frame(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_frame)(CGFloat x, CGFloat y, CGFloat width, CGFloat height);
/** center(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_center)(CGFloat x, CGFloat y);
/** 背景颜色(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_backgroundColor)(UIColor *backgroundColor);
/** 色调 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_tintColor)(UIColor *tintColor);
/** tag(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_tag)(NSInteger tag);
/** 添加到父视图(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addToSuperView)(UIView *superView);
/** 添加约束 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_makeConstraints)(void(^mas_makeConstraints)(MASConstraintMaker *make));
/** hidden(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_hidden)(BOOL hidden);
/** 交互启用(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_userInteractionEnabled)(BOOL userInteractionEnabled);
/** 添加手势 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addGestureRecognizer)(UIGestureRecognizer *ges, id target, SEL action);
/** 角标文字 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_badgeText)(NSString *badgeText);
/** 角标距离superView的top */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_badgeEdge)(CGFloat badgeEdge);
/** 角标文字颜色 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_badgeTextColor)(UIColor *badgeTextColor);
/** 角标背景颜色 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_badgeBackgroundColor)(UIColor *badgeBackgroundColor);
/** 底图(view)，不可与ms_colors同时设置，否则将被ms_colors覆盖  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_layerImage)(UIImage *image);


#pragma mark - 圆角、边线，依赖控件frame
/** 圆角半径(view) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_cornerRadii)(CGFloat cornerRadii);
/** 左上角半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_topLeftCornerRadii)(CGFloat topLeftCornerRadii);
/** 左下角半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_bottomLeftCornerRadii)(CGFloat bottomLeftCornerRadii);
/** 右下角半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_bottomRightCornerRadii)(CGFloat bottomRightCornerRadii);
/** 右上角半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_topRightCornerRadii)(CGFloat topRightCornerRadii);
/** 边线宽(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_lineWidth)(CGFloat lineWidth);
/** 边线颜色(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_lineColor)(UIColor *lineColor);
/** 虚线的偏移量*/
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_lineDashPhase)(CGFloat lineDashPhase);
/** 虚线-线长&线间距，lineDashPattern为线性模版，这是一个NSNumber的数组，索引从1开始记，奇数位数值表示实线长度，偶数位数值表示空白长度 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_lineDashPattern)(NSArray<NSNumber *> *lineDashPattern);
/** 绘制圆角和边线（依赖控件frame ！！！） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_drawCornerAndBorderLine)(void);


#pragma mark - 直角边线
/** 直角边线边类型，上下左右(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_borderSideType)(MSBorderSideType borderSideType);
/** 绘制直角边线（依赖控件frame ！！！） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_drawBorderLine)(void);


#pragma mark - 阴影
/** 阴影-颜色(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowColor)(UIColor *shadowColor);
/** 阴影-偏移(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowOffset)(CGSize shadowOffset);
/** 阴影-不透明度(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowOpacity)(CGFloat shadowOpacity);
/** 阴影-半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowRadius)(CGFloat shadowRadius);
/** 阴影-角半径(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowCornerRadius)(CGFloat shadowCornerRadius);
/** 绘制阴影（依赖控件frame ！！！） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_drawShadow)(void);


#pragma mark - 渐变色
/** 渐变色-颜色数组(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_colors)(NSArray<UIColor *> * _Nullable colors);
/** 渐变色-起始点(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_startPoint)(CGPoint startPoint);
/** 渐变色-结束点(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_endPoint)(CGPoint endPoint);
/** 渐变色-分割点(view)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_locations)(NSArray<NSNumber *> * _Nullable locations);
/** 渐变色-贝塞尔曲线 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_shadowPath)(id shadowPath);
/** 绘制渐变色（依赖控件frame ！！！） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_drawGradientLayer)(void);


#pragma mark - layer animation
/** 
 layer添加CABasicAnimation动画
 
 常用的animationWithKeyPath值的总结：
 ransform.scale                      比例转换                                        @(0.8)
 transform.scale.x                  宽的比例                                        @(0.8)
 transform.scale.y                  高的比例                                        @(0.8)
 transform.rotation.x               围绕x轴旋转                                  @(M_PI)
 transform.rotation.y               围绕y轴旋转                                  @(M_PI)
 transform.rotation.z               围绕z轴旋转                                  @(M_PI)
 cornerRadius                        圆角的设置                                    @(50)
 backgroundColor                  背景颜色的变化                             (id)[UIColor purpleColor].CGColor
 bounds                                  大小，中心不变                             [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
 position                                 位置(中心点的改变)                       [NSValue valueWithCGPoint:CGPointMake(300, 300)];
 contents                                内容，比如UIImageView的图片    imageAnima.toValue = (id)[UIImage imageNamed:@"to"].CGImage;
 opacity                                  透明度                                           @(0.7)
 contentsRect.size.width        横向拉伸缩放                               @(0.4)最好是0~1之间的
 strokeEnd                              曲线绘制过程                               @0
 locations                               渐变色-分割点变化                        @[@0, @0, @0.25] 
 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addLayerAnimation)(NSString *lineAnimation_keyPath, CFTimeInterval duration, id fromValue, id toValue, CGFloat repeatCount);
/** 移除layer的CABasicAnimation动画 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_removeLayerAnimation)(NSString *lineAnimation_keyPath);


#pragma mark - label、textField、textView 公有
/** 文字(label、textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_text)(NSString *text);
/** 富文本(label、textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_attributedText)(NSAttributedString *attributedText);
/** 字体(label、textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_font)(UIFont *font);
/** 文字颜色(label、textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_textColor)(UIColor *textColor);
/** 文字对齐方式(label、textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_textAlignment)(NSTextAlignment textAlignment);


#pragma mark - button、textfield 公有
/** 添加点击事件(UIButton、UITextField) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addTarget)(id target, SEL action);


#pragma mark - textField、textView 公有
/** 键盘类型 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_keyboardType)(UIKeyboardType keyboardType);
/** 成为第一响应者 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_becomeFirstResponder)(void);
/** 自定义键盘(textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_inputView)(UIView *inputView);
/** 键盘上面自定义附件视图(textField、textView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_inputAccessoryView)(UIView *inputAccessoryView);


#pragma mark - textField、textView、tableView、collectionView、scrollView
/** 设置delegate(textField、textView、tableView、collectionView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_delegate)(id delegate);


#pragma mark - tableView、collectionView 公有
/** 设置dataSource(tableView、collectionView) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_dataSource)(id dataSource);
/** 注册cell（tableView、collectionView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_registerCell)(id cellClass, NSString *identifier);


#pragma mark -
#pragma mark - label
/** 行数(label) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_numberOfLines)(NSInteger numberOfLines);
/** 断句模式(label) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_lineBreakMode)(NSLineBreakMode lineBreakMode);
/** HTML字符串 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_htmlText)(NSString *htmlString);


#pragma mark - button
/** 标题(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_title)(NSString *title, UIControlState state);
/** 标题(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_attributedTitle)(NSAttributedString *title, UIControlState state);
/** 标题字体(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_titleFont)(UIFont *font);
/** 标题颜色(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_titleColor)(UIColor *color, UIControlState state);
/** 图片(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_image)(UIImage *image, UIControlState state);
/** 背景图片(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_backgroundImage)(UIImage *image, UIControlState state);
/** 背景图片(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_backgroundImageURLString)(NSString *url, UIImage *placeholderImage, UIControlState state);
/** 按钮图片文字排列类型(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_buttonType)(MSButtonModel model);
/** 图片与文字间距(button) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_space)(CGFloat space);
/** 更新按钮文字和图片位置（依赖imageView和titleLabel） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_resetButton)(void);


#pragma mark - scrollView
/** 关闭自动调整滚动指示器集（scrollView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_automaticallyAdjustsScrollIndicatorInsets)(void);
/** 方向锁，拖动时锁定垂直或水平滚动 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_directionalLockEnabled)(BOOL bounces);
/** bounces */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_bounces)(BOOL bounces);
/** 如果“YES”且“bounces”为“YES”，则即使内容小于边界，也允许垂直拖动 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_alwaysBounceVertical)(BOOL alwaysBounceVertical);
/** 如果“YES”且“bounces”为“YES”，则即使内容小于边界，也允许水平拖动 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_alwaysBounceHorizontal)(BOOL alwaysBounceHorizontal);
/** pagingEnabled */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_pagingEnabled)(BOOL pagingEnabled);
/** scrollEnabled */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_scrollEnabled)(BOOL scrollEnabled);
/** showsVerticalScrollIndicator */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_showsVerticalScrollIndicator)(BOOL showsVerticalScrollIndicator);
/** showsVerticalScrollIndicator */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_showsHorizontalScrollIndicator)(BOOL showsHorizontalScrollIndicator);
/** contentOffset */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_contentOffset)(CGPoint point);
/** contentSize */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_contentSize)(CGSize size);
/** contentInset */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_contentInset)(UIEdgeInsets edgeInsets);


#pragma mark - textField
/** 占位符(textField) */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_placeholder)(NSString *placeholder);
/** 富文本占位符(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_attributedPlaceholder)(NSAttributedString *attributedPlaceholder);
/** 开始编辑时是否清除(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_clearsOnBeginEditing)(BOOL clearsOnBeginEditing);
/** 删除按钮模式(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_clearButtonMode)(UITextFieldViewMode clearButtonMode);
/** 左侧视图(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_leftView)(UIView *leftView);
/** 左侧视图模式(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_leftViewMode)(UITextFieldViewMode leftViewMode);
/** 右侧视图(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_rightView)(UIView *rightView);
/** 右侧视图模式(textField)  */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_rightViewMode)(UITextFieldViewMode rightViewMode);


#pragma mark - tableView
/** default is UITableViewAutomaticDimension（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_rowHeight)(CGFloat rowHeight);
/** default is UITableViewAutomaticDimension（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_sectionHeaderHeight)(CGFloat sectionHeaderHeight);
/** default is UITableViewAutomaticDimension（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_sectionFooterHeight)(CGFloat sectionFooterHeight);
/** default is UITableViewAutomaticDimension, set to 0 to disable（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_estimatedRowHeight)(CGFloat estimatedRowHeight);
/** default is UITableViewAutomaticDimension, set to 0 to disable（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_estimatedSectionHeaderHeight)(CGFloat estimatedSectionHeaderHeight);
/** default is UITableViewAutomaticDimension, set to 0 to disable（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_estimatedSectionFooterHeight)(CGFloat estimatedSectionFooterHeight);
/** default is YES. Controls whether rows can be selected when not in editing mode */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_allowsSelection)(BOOL allowsSelection);
/** default is NO. Controls whether rows can be selected when in editing mode */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_allowsSelectionDuringEditing)(BOOL allowsSelectionDuringEditing);
/** default is NO. Controls whether multiple rows can be selected simultaneously */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_allowsMultipleSelection)(BOOL allowsMultipleSelection);
/** default is NO. Controls whether multiple rows can be selected simultaneously in editing mode */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_allowsMultipleSelectionDuringEditing)(BOOL allowsMultipleSelectionDuringEditing);
/** 分割线类型 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_separatorStyle)(UITableViewCellSeparatorStyle separatorStyle);
/** 分割线颜色 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_separatorColor)(UIColor *separatorColor);
/** 分割线缩进（tableView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_separatorInset)(UIEdgeInsets separatorInset);
/** tableHeaderView */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_tableHeaderView)(UIView *tableHeaderView);
/** tableFooterView */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_tableFooterView)(UIView *tableFooterView);
/** 注册分组头部尾部视图 */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_registerHeaderFooterView)(id aClass, NSString *identifier);


#pragma mark - collectionView
/** layout（collectionView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_collectionViewLayout)(UICollectionViewLayout *collectionViewLayout);
/** 注册集合视图页眉页脚UICollectionElementKindSectionHeader、UICollectionElementKindSectionFooter（collectionView） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_registerSupplementaryViewClass)(id viewClass, NSString *elementKind, NSString *identifier);


#pragma mark - alertController
/** 添加按钮（alertController） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addAction)(UIAlertAction *action);
/** alert title字体和颜色（alertController） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_titleFontAndColor)(UIFont *font, UIColor *color);
/** alert message字体、颜色和对齐方式（alertController）*/
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_messageFontColorAndAlignment)(UIFont *font, UIColor *color, NSTextAlignment alignment);


#pragma mark - alertAction
/** 添加到alertController（alertAction） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_addToAlert)(UIAlertController *alert);
/** alert按钮文字颜色（alertAction） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_titleTextColor)(UIColor *color);


#pragma mark - NSMutableAttributedString
/** 设置文字字体（NSMutableAttributedString） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_fontAttribute)(UIFont *font, NSRange range);
/** 设置文字颜色（NSMutableAttributedString） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_colorAttribute)(UIColor *color, NSRange range);
/** 设置字间距（NSMutableAttributedString） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_kernAttribute)(NSNumber *Kern, NSRange range);
/** 设置段落（NSMutableAttributedString） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_paragraphStyleAttribute)(NSTextAlignment alignment, CGFloat lineSpacing, NSLineBreakMode lineBreakMode, NSRange range);
/** 设置删除线（NSMutableAttributedString） */
@property (nonatomic, copy, readonly) MSChainMaker *(^ms_strikethroughStyleAttribute)(UIColor *color, NSRange range);

@end

NS_ASSUME_NONNULL_END
